home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Comms & Internet / LinkConverter 1.1.2 / Dialog Director v0.7 / Examples / Database.as < prev    next >
Encoding:
Text File  |  1998-01-12  |  4.3 KB  |  136 lines  |  [TEXT/ToyS]

  1. property dbName : "DD Address Book"
  2. property dbDesc : [¬
  3.     {name:"Last name", style:text field, width:20}, ¬
  4.     {name:"First name", style:text field, width:20}, ¬
  5.     {name:"Street address", style:text field, width:20}, ¬
  6.     {name:"City", style:text field, width:20}, ¬
  7.     {name:"County", style:text field, width:20}, ¬
  8.     {name:"Post Code", style:text field, width:10}, ¬
  9.     {name:"Company affiliation", style:text field, width:20}, ¬
  10.     {name:"Work phone#", style:text field, width:20}, ¬
  11.     {name:"Home phone#", style:text field, width:20}, ¬
  12.     {name:"Fax phone#", style:text field, width:20} ¬
  13.         ]
  14. --{name:"Test Field", style:text field, width:10}, ¬
  15. property dbButtons : ["Store", "New", "Find", "Prev", "Next"]
  16. property dbFonts : [{name:"Geneva", size:9, style:plain}]
  17. property dbData : [¬
  18.     "Hyde    Chris    1701 Enterprise Street    London    Babylon 5    DS9 TNG    HyLight    BBC2, 6.00pm, Wednesday    Channel 4, 10.30pm    BBC2, 6.30pm, Sunday", ¬
  19.     "1    2    3    4    5    6    7    8    9    10", ¬
  20.     "0    1    2    3    4    5    6    7    8    9"]
  21. property dbNewRec : "a    b    c    d    e    f    g    h    i    j"
  22.  
  23. property nameWidth : 0
  24. property winH : 0
  25. property winV : 0
  26. property nWidth : 0
  27. property lineV : 20
  28. property lineCount : 0
  29.  
  30. set nWidth to 8 -- width of "m" font font0's name size (font0's size) face font0's style
  31. if nameWidth = 0 then
  32.     repeat with f in dbDesc
  33.         set w to 8 + (f's name's length) * 5 -- (width of f's name font font0's name size (font0's size) face font0's style)
  34.         if w > nameWidth then set nameWidth to w
  35.     end repeat
  36. end if
  37. if winH = 0 then
  38.     repeat with f in dbDesc
  39.         set w to f's width
  40.         if w > winH then set winH to w
  41.     end repeat
  42.     set winH to 20 + nameWidth + winH * nWidth
  43.     set w to 10 + (dbButtons's length) * 60
  44.     if w > winH then set winH to w
  45. end if
  46. set lineCount to (dbDesc's length) + 2
  47. if winV = 0 then set winV to lineCount * lineV + 20
  48.  
  49. set dItems to []
  50. repeat with i from 1 to dbButtons's length
  51.     set dItems to dItems & [MakeButton(dbButtons's item i, i)]
  52. end repeat
  53. --set dItems to dItems & [MakeButton(dbButtons's item i, i)]
  54. set y to 10 + (lineCount - 2) * lineV
  55. set dItems to dItems & [{class:static text, contents:"#", bounds:[winH - 100, y, winH - 10, y + 16], justification:right}]
  56.  
  57. set y to 0
  58. repeat with f in dbDesc
  59.     set dItems to dItems & [Field(f, y)]
  60.     set y to y + 1
  61. end repeat
  62.  
  63. global idx
  64. set idx to 1
  65. set recCount to dbData's length
  66. --get dd auto dialog {size:[winH, winV], name:dbName, style:movable modal, contents:dItems, font:font0} with greyscale
  67. dd install with fonts dbFonts with grayscale
  68. set d to dd make dialog {size:[winH, winV], name:dbName, style:standard window, contents:dItems, closeable:true}
  69. GetRecord(idx, d)
  70. repeat
  71.     dd set contents of item 6 of d to "" & idx & " of " & recCount
  72.     dd set enabled of items 4 thru 5 of d to [idx ≠ 1, idx ≠ recCount]
  73.     set i to dd interact with user
  74.     -- Store, New, Find, Prev, Next
  75.     if i = 1 then
  76.         PutRecord(idx, d)
  77.     else if i = 2 then
  78.         set dbData to dbData & dbNewRec
  79.         set idx to dbData's length
  80.         set recCount to idx
  81.         GetRecord(idx, d)
  82.     else if i = 3 then
  83.     else if i = 4 then
  84.         if idx > 1 then
  85.             set idx to idx - 1
  86.             GetRecord(idx, d)
  87.         end if
  88.     else if i = 5 then
  89.         if idx < recCount then
  90.             set idx to idx + 1
  91.             GetRecord(idx, d)
  92.         end if
  93.     else if i = -1 then
  94.         exit repeat
  95.     end if
  96. end repeat
  97. dd uninstall
  98. return --result
  99.  
  100. on GetRecord(idx, d)
  101.     set AppleScript's text item delimiters to [tab]
  102.     set dVals to text items of item idx of dbData
  103.     dd set value of items 7 thru 16 of d to dVals
  104.     set AppleScript's text item delimiters to []
  105. end GetRecord
  106.  
  107. on PutRecord(idx, d)
  108.     set dVals to dd get value of items 7 thru 16 of d
  109.     set R to item 1 of dVals
  110.     repeat with f in items 2 thru -1 of dVals
  111.         set R to R & tab & f
  112.     end repeat
  113.     set item idx of dbData to R
  114. end PutRecord
  115.  
  116. on Field(f, y)
  117.     if f's style = text field then
  118.         set R to DMake(text field, f's name, nameWidth, y, nWidth * (f's width), 12)
  119.         return R & {name bounds:[10, 10 + y * lineV, 10 + nameWidth, 10 + y * lineV + 12]}
  120.         --set r's name bounds to [10, 10 + y * lineV, 10 + nameWidth, 10 + y * lineV + 12]
  121.         --return r
  122.     else
  123.         -- other field types
  124.     end if
  125. end Field
  126.  
  127. on DMake(T, n, x, y, w, h)
  128.     set x to 10 + x
  129.     set y to 10 + y * lineV
  130.     return {class:T, bounds:[x, y, x + w, y + h], name:n}
  131. end DMake
  132.  
  133. on MakeButton(n, i)
  134.     return DMake(push button, n, (i - 1) * 60, lineCount - 1, 50, 20)
  135.     --return DMake(push button, n, winH - 20 - (i - 1) * 60, lineCount - 1, 50, 20)
  136. end MakeButton